import Vue from 'vue'
import Router from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home'
import Welcome from "../components/Welcome";
import UserKeyword from "../components/UserKeyword";
import keywordLibrary from "../components/keywordLibrary";
import Testcase from "../components/Testcase"
import Testplan from "../components/Testplan"
import UserManagement from "../components/UserManagement";
import EndRunner from "../components/EndRunner";

Vue.use(Router)


const router = new Router({
    routes:[
        {path: '/', redirect: '/welcome'},
        {path: '/login', component:Login},
        {path: '/home', redirect:'/welcome',component:Home,
            children:[
                {path:'/welcome', component:Welcome},
                {path:'/userkeyword', component: UserKeyword},
                {path:'/keywordLibrary', component:keywordLibrary},
                {path:'/testcase',component:Testcase},
                {path:'/testplan',component:Testplan},
                {path:'/userManagement',component:UserManagement},
                {path:'/endRunner',component:EndRunner}
            ]
        }
    ]
})

router.beforeEach((to,from, next)=>{

    if(to.path ==='/login') return next();

    const tokenValue = window.sessionStorage.getItem('token');

    if(!tokenValue){

        return next('/login');
    }

    next();

})

export default router


